home *** CD-ROM | disk | FTP | other *** search
- // Here is a simple test of the graphics system
- // Written by Yuri Kiselev, 1994.
-
- #pragma -ml
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <dos.h>
- #include <conio.h>
- #include <mem.h>
- #include <alloc.h>
-
- #include "graph.h"
-
- void pixelplay(BYTE colors)
- {
- do {
- putpixel(random(getmaxx()),random(getmaxy()),random(colors));
- } while (!kbhit());
- getch();
- }
-
- void lineplay(BYTE colors)
- {
- do {
- setcolor(random(colors));
- line(random(getmaxx()),random(getmaxy()),
- random(getmaxx()),random(getmaxy()));
-
- } while (!kbhit());
- getch();
- }
-
- void barplay(BYTE colors) //Draw random bars on the screen
- {
- int maxheight,maxwidth,x,y,x1,y1;
- maxwidth = getmaxx();
- maxheight = getmaxy();
- do {
- setfillstyle(random(11),random(colors));
- x = random(maxwidth);
- y = random(maxheight);
- x1 = random(maxwidth);
- y1 = random(maxheight);
- if (x > x1)
- asm {
- mov ax,x
- xchg ax,x1
- mov x,ax
- }
- if (y > y1)
- asm {
- mov ax,y
- xchg ax,y1
- mov y,ax
- }
- bar(x,y,x1,y1);
- } while (!kbhit());
- getch();
- }
-
- void polyplay(BYTE colors)
- {
- pointtype poly[20];
- int maxpts = 5;
- int i;
- do {
- setfillstyle(random(11),random(colors));
- setcolor(random(colors));
- for(i=0;i<maxpts;i++)
- {
- poly[i].x = random(getmaxx());
- poly[i].y = random(getmaxy());
- }
- poly[maxpts].x = poly[0].x;
- poly[maxpts].y = poly[0].y;
- fillpoly(maxpts+1,poly);
- } while (!kbhit());
- getch();
- }
-
- void imageplay(void)
- {
- int sizex = 80,sizey = 100;
- int x,y,x1,y1;
- void* savebuffer,*imagebuffer;
- setfillstyle(8,2);
- bar(0,0,getmaxx(),getmaxy());
- setfillstyle(2,12);
- bar(0,0,sizex,sizey);
- imagebuffer = malloc(64000);
- savebuffer = malloc(64000);
- getimage(0,0,sizex,sizey,imagebuffer);
- do {
- x = random(getmaxx());
- y = random(getmaxy());
- getimage(x,y,x+sizex,y+sizey,savebuffer);
- putimage(x,y,imagebuffer);
- delay(100);
- putimage(x,y,savebuffer);
- } while (!kbhit());
- getch();
- free(savebuffer);
- free(imagebuffer);
- }
-
- int poly[10] = {10,10,40,12,45,39,9,41,10,10};
- void main(void)
- {
- randomize();
- if (graphinit() < 0) {printf("Graphics not initialize."); exit(1);}
-
- // 16 colors video mode
- pixelplay(15);
- lineplay(15);
- barplay(15);
- polyplay(15);
- imageplay();
-
- // 320x200x256 video mode
- switchmode(VGA256);
- pixelplay(255);
- lineplay(255);
- barplay(255);
- polyplay(255);
- imageplay();
-
- // 640x480x256 video mode
- switchmode(SVGA640x480x256);
- pixelplay(255);
- lineplay(255);
- barplay(255);
- polyplay(255);
- imageplay();
- closegraph();
- }